package com.snake.mylibrary.mina;

import org.apache.mina.core.session.IoSession;



public class SessionManager {
    private static volatile SessionManager sSessionManager;

    private IoSession mSession;

    private SessionManager(){

    }

    public static SessionManager getInstance(){
        if(sSessionManager==null){
            sSessionManager = new SessionManager();
        }
        return sSessionManager;
    }


    public void setSession(IoSession session) {
        mSession = session;
    }

    public void writeToServer(Object msg){
        if(mSession!=null){
            mSession.write(msg);
        }
    }

    public void closeSession(){
        if(mSession!=null){
            mSession.closeOnFlush();
        }
    }

    public void removeSession(){
        this.mSession = null;
    }
}
